package com.trmp.sys.login.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.google.gson.Gson;
import com.trmp.sys.menuMng.model.MenuRsBean;
import com.trmp.sys.menuMng.service.MenuInfoService;
import com.trmp.sys.userMng.entity.UserInfo;

@Controller
public class MainController
{
	

	@Autowired
	private MenuInfoService menuinfoservice;
	
	@RequestMapping("/system/loadMain.do")
	public String load()
	{
		return "/center";
	}
	
	
	
	@RequestMapping("/loadMainpage.do")
	public String loadMainpage()
	{
		return "main";
	}
	
	@RequestMapping("/loadTop.do")
	public String loadTop(ModelMap modelMap,HttpServletRequest request)
	{
		modelMap.put("loginname",((UserInfo) request.getSession().getAttribute("user")).getLoginName());
		return "top";
	}
	
	@RequestMapping("loadMiddle.do")
	public String loadMiddle()
	{
		
		return "middle";
	}
	
	@RequestMapping("loadLeft.do")
	public String loadLeft(HttpServletRequest request,ModelMap modelMap)
	{
		long userID = ((UserInfo) request.getSession().getAttribute("user")).getUserId();
		MenuRsBean mb = menuinfoservice.getMenuInfoJsonList(userID);
		Gson gson = new Gson();
		String m1 = gson.toJson(mb.getMenuLevel1());
		String m2 = gson.toJson(mb.getMenuLevel2());
		String m3 = gson.toJson(mb.getMenuLevel3());
		
		modelMap.addAttribute("mL1", m1);
		modelMap.addAttribute("mL2", m2);
		modelMap.addAttribute("mL3", m3);
		return "left";
	}
	
	@RequestMapping("loadRight.do")
	public String loadRight()
	{
		
		return "system/right";
	}
	
	@RequestMapping("loadBottom.do")
	public String loadBottom()
	{
		
		return "bottom";
	}
	
}
